package com.eattravel.controller;
/*
    wy 七牛云Controller
    描述：上传图片拿这个模仿就行
    最后修改时间：9.19/16.02
*/
import com.eattravel.constant.QiniuYun;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;

@Controller
public class QiNiuController {

    @Autowired
    private QiniuYun qiniuyun;

    @RequestMapping(value = "/testUpload")
    @ResponseBody
    public String uploadImage(@RequestParam("file")List<MultipartFile> files,HttpServletRequest request) {
        if (files.size() == 0) {
            return "error";
        }
        try {
            String fileUrl = "";
            if (files != null) {
                for (MultipartFile file : files) {
                    /* 3.1保存图片 */
                    fileUrl = fileUrl + "================" +qiniuyun.saveImage(file);
                }
            }
            return "success, imageUrl = " + fileUrl;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "fail";

    }
}
